// const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
const path = require('path')

console.log('------------------->', path.resolve(__dirname, 'node_modules/monaco-volar/dist/worker/vue.worker.js'))

module.exports = {
  transpileDependencies: [
    '@volar/monaco',
    '@volar/language-core',
    '@volar/language-service',
    'hussar-monaco-vue',
    'monaco-editor-textmate',
    'monaco-volar',
    'typescript',
    'volar-service-typescript',
    'vscode-uri'
  ],
  chainWebpack (config) {
    // config.resolve.set('path', 'path-browserify')
    // config.module
    //   .rule('js')
    //   .test(/\.js$/)
    //   .include
    //   .add(path.resolve(__dirname, 'node_modules/monaco-volar/dist/worker/vue.worker.js'))
    //   .add(path.resolve(__dirname, 'node_modules/monaco-editor-textmate/dist/index.js'))
    //   .add(path.resolve(__dirname, 'node_modules/@volar/monaco/out/utils/provider.js'))
    //   .add(path.resolve(__dirname, 'node_modules/@volar/monaco/out/editor.js'))
    //   .end()
    //   .use('babel-loader')
    //   .loader('babel-loader')
    //   .options({
    //     presets: ['@babel/preset-env'],
    //     plugins: [
    //       '@babel/plugin-proposal-optional-chaining',
    //       '@babel/plugin-proposal-nullish-coalescing-operator'
    //     ]
    //   })
    //   .end()
    config.module
      .rule('wasm')
      .test(/\.wasm$/)
      .type('javascript/auto')
      .use('file-loader')
      .loader('file-loader')
      .tap(options => ({
        name: '[name].[ext]'
      }))
      .end()
    // config.module
    //   .rule('wasm')
    //   .test(/\.wasm$/)
    //   .type('javascript/auto')
    //   .use('wasm-loader')
    //   .loader('wasm-loader')
    //   .end()
    //   .parser({ wasm: { type: 'webassembly/experimental' } })
    //   .end()
    // config.module
    //   .rule('worker')
    //   .test(/\.worker\.js$/)
    //   .use('worker-loader')
    //   .loader('worker-loader')
    //   .end()
    config.module
      .rule('worker')
      .test(/\.worker\.js$/)
      .exclude.add(/node_modules/)
      .end()
      .use('worker-loader')
      .loader('worker-loader')
      .end()
  }
}
